package com.sctvcloud.dongqu.ui.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.dongqu.R;
import com.sctvcloud.dongqu.base.BaseActivity;
import com.sctvcloud.dongqu.beans.AFileItem;
import com.sctvcloud.dongqu.ui.activities.AnchorHomePageActivity;
import com.sctvcloud.dongqu.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/13 0013.
 */

public class AnchorFilesHolder extends BaseAnchorHolder<AFileItem> implements View.OnClickListener {
    @BindView(R.id.item_anchor_file_avatar)
    protected CustomEXImageView avatar;
    @BindView(R.id.item_anchor_file_name)
    protected CustomFontTextView name;
    @BindView(R.id.item_anchor_file_column)
    protected CustomFontTextView columnName;
    @BindView(R.id.item_anchor_file_intro)
    protected CustomFontTextView intro;
    private String title;
    private String anchorUrl;

    public AnchorFilesHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(AFileItem aFileItem) {
        name.setText(!TextUtils.isEmpty(aFileItem.getAnchorName()) ? aFileItem.getAnchorName() : "");
        columnName.setText(!TextUtils.isEmpty(aFileItem.getCurrentWork()) ? aFileItem.getCurrentWork() : "");
        intro.setText(!TextUtils.isEmpty(aFileItem.getAnchorIntro()) ? aFileItem.getAnchorIntro() : "");
        anchorUrl = aFileItem.getAnchorInfoUrl();
        title = aFileItem.getAnchorName();
        if (!TextUtils.isEmpty(aFileItem.getAnchorAvatar())) {
            GlideUtil.getGlideWith34Def(context, aFileItem.getAnchorAvatar())
                    //.transform(new GlideRoundTransformUtil(context, 5))
                    .into(avatar);
        } else {
            avatar.setImageResource(R.mipmap.icon_def_3_4);
        }
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(context, AnchorHomePageActivity.class);
        if (!TextUtils.isEmpty(anchorUrl) && anchorUrl.endsWith(".json")) {
            intent.putExtra(BaseActivity.EX_URL, anchorUrl);
            intent.putExtra(BaseActivity.EX_TITLE, title);
            context.startActivity(intent);
        } else {

        }

    }
}
